<?php
declare(strict_types=1);

namespace App\Controller;

use App\Request\UserRequest;
use http\Env\Request;
use Hyperf\ApiDocs\Annotation\ApiFormData;
use Hyperf\ApiDocs\Annotation\ApiOperation;
use Hyperf\ApiDocs\Annotation\ApiResponse;
use Hyperf\Di\Annotation\Inject;
use Hyperf\DTO\Annotation\Contracts\RequestFormData;
use Hyperf\DTO\Mapper;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Mrx\Core\Controller\AbstractController;
use Mrx\Core\Dto\User\MemberDto;
use Mrx\Core\JsonRpc\User\UserServiceInterface;

/**
 * @Desc:用户相关接口
 * @Class: UserController
 * @Package: App\Controller
 * @Author: mrx
 * @CreateTime: 2023-07-13  14:44
 * @Version: 1.0
 */
#[Controller(prefix: '/User')]
class UserController extends AbstractController
{
    #[Inject]
    protected UserServiceInterface $userService;


    /**
     * @Desc:获取用户信息
     * @Funtion: userInfo
     * @Author: mrx
     * @CreateTime: 2023-07-13
     * @return void
     */
    #[GetMapping(path: 'userInfo')]
    public function userInfo()
    {
        return $this->response->success($this->userService->getUserInfoByUserId(1));
    }

    #[PostMapping(path: 'register')]
    #[ApiOperation('注册', security: false)]
    #[ApiFormData(name: 'username', required: true, type: 'string', description: '账号')]
    #[ApiFormData(name: 'mobile', required: true, type: 'string', description: '手机号')]
    public function register(UserRequest $request)
    {
        $memberDto = new MemberDto( [
            'username' => $request->input('username'),
            'mobile' => $request->input('mobile')
        ]);
        return $this->userService->register($memberDto);
    }
}